package com.zzsy.carosshopprojects.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.king.base.adapter.ViewHolderRecyclerAdapter;
import com.king.base.adapter.holder.ViewHolder;
import com.yatoooon.screenadaptation.ScreenAdapterTools;
import com.zzsy.carosshopprojects.R;
import com.zzsy.carosshopprojects.bean.CreateFuCardBean;
import com.zzsy.carosshopprojects.util.StringUtils;

import java.util.List;

public class AddCardAdapter extends ViewHolderRecyclerAdapter<CreateFuCardBean> {


    public AddCardAdapter(Context context, List<CreateFuCardBean> listData, int layoutId) {
        super(context, listData, layoutId);
    }

    @Override
    public View buildConvertView(LayoutInflater layoutInflater, ViewGroup parent, int viewType) {
        View view = layoutInflater.inflate(R.layout.adapter_addcard, null);
        ScreenAdapterTools.getInstance().loadView(view);
        return view;
    }

    @Override
    public void bindViewDatas(ViewHolder helper, CreateFuCardBean addCardBean, int positions) {
        int number = addCardBean.getCountLimit();
        int openingCount = addCardBean.getOpeningCount();
        String cardType = addCardBean.getName();
        String subCardType = addCardBean.getId();
        helper.setText(R.id.tv_card_type,cardType);
        if(!StringUtils.isEmpty(subCardType)){
            if("1".equals(subCardType)){
                 helper.setImageResource(R.id.img_card,R.mipmap.mother_card);
                 helper.setText(R.id.tv_card_type,"父母卡");
            }else if("3".equals(subCardType)){
                helper.setImageResource(R.id.img_card,R.mipmap.qingqing_card);
                helper.setText(R.id.tv_card_type,"伴侣卡");
            }else if("2".equals(subCardType)){
                helper.setImageResource(R.id.img_card,R.mipmap.son_card);
                helper.setText(R.id.tv_card_type,"子女卡");
            }else if("4".equals(subCardType)){
                helper.setImageResource(R.id.img_card,R.mipmap.yuangong_card);
                helper.setText(R.id.tv_card_type,"企业卡");
            }else{
                helper.setImageResource(R.id.img_card,R.mipmap.other_card);
                helper.setText(R.id.tv_card_type,"其他卡");
            }
        }

        int num = number - openingCount;
        if(num >= 0){
            helper.setText(R.id.tv_card_num,"可赠予"+num+"张");
        }else{
            helper.setText(R.id.tv_card_num,"可赠予0张");
        }
        helper.getConvertView().setOnClickListener(v -> onClickItemListener.onClick(positions,num));

    }
    public interface OnClickItemListener{
        void onClick(int position,int num);
    }

    private OnClickItemListener onClickItemListener;

    public void setOnClickItemListener(OnClickItemListener onClickItemListener) {
        this.onClickItemListener = onClickItemListener;
    }


}
